package com.digitalchina.lxnsy.api;

import android.app.Activity;
import android.os.Handler;

import com.digitalchina.lxnsy.constant.MSG;
import com.digitalchina.lxnsy.constant.URL;
import com.digitalchina.lxnsy.toolkit.EncryptUtil;
import com.digitalchina.lxnsy.toolkit.OkHttpUtil;
import com.digitalchina.lxnsy.xml.UserXML;
import com.lzy.okhttputils.model.HttpParams;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.api
 * 创建人：郑皓
 * 创建时间：2017/10/27 15:03
 * 修改备注：
 * ================================================
 */
public class BusinessPayPassword {

    /**
     * 设置支付密码--发送验证码
     *
     * @param activity
     * @param phoneNumber 电话号码
     * @param handler
     */
    public static void sendVerifyCode(Activity activity, String phoneNumber, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("phoneNumber", phoneNumber);

        OkHttpUtil.post(activity, URL.URL_PAY_PASSWORD_SEND_CODE, "获取验证码", params, handler, MSG.MSG_PAY_PASSWORD_SEND_CODE_SUCCESS, MSG.MSG_PAY_PASSWORD_SEND_CODE_FIELD);

    }

    /**
     * 设置支付密码--验证用户输入的验证码
     *
     * @param activity
     * @param phoneNumber
     * @param verifyCode  验证码
     * @param handler
     */
    public static void sendVercheckVerifyCodeifyCode(Activity activity, String phoneNumber, String verifyCode, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("phoneNumber", phoneNumber);
        params.put("verifyCode", verifyCode);

        OkHttpUtil.post(activity, URL.URL_PAY_PASSWORD_CHECK_CODE, "验证中...", params, handler, MSG.MSG_PAY_PASSWORD_CHECK_CODE_SUCCESS, MSG.MSG_PAY_PASSWORD_CHECK_CODE_FIELD);

    }

    /**
     * 修改用户支付密码
     *
     * @param activity
     * @param oldPayPassword 原密码
     * @param newPayPassword 新密码
     * @param affirmPassword 确认密码
     * @param handler
     */
    public static void updatePayPassword(Activity activity, String oldPayPassword, String newPayPassword, String affirmPassword, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("userAccId", UserXML.getUserId(activity));
        params.put("oldPayPassword", EncryptUtil.SHA1(oldPayPassword));
        params.put("newPayPassword", EncryptUtil.SHA1(newPayPassword));
        params.put("affirmPassword", EncryptUtil.SHA1(affirmPassword));

        OkHttpUtil.post(activity, URL.URL_UPDATE_PAY_PASSWORD, "", params, handler, MSG.MSG_UPDATE_PAY_PASSWORD_SUCCESS, MSG.MSG_UPDATE_PAY_PASSWORD_FIELD);

    }


    /**
     * 设置用户支付密码
     *
     * @param activity
     * @param payPassword
     * @param affirmPassword
     * @param handler
     */
    public static void setPayPassword(Activity activity, String payPassword, String affirmPassword, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("userAccId", UserXML.getUserId(activity));
        params.put("payPassword", EncryptUtil.SHA1(payPassword));
        params.put("affirmPassword", EncryptUtil.SHA1(affirmPassword));

        OkHttpUtil.post(activity, URL.URL_SET_PAY_PASSWORD, "", params, handler, MSG.MSG_SET_PAY_PASSWORD_SUCCESS, MSG.MSG_SET_PAY_PASSWORD_FIELD);

    }

    /**
     * 忘记密码
     *
     * @param activity
     * @param payPassword
     * @param affirmPassword
     * @param handler
     */
    public static void setPayPasswordNew(Activity activity, String payPassword, String affirmPassword, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("userAccId", UserXML.getUserId(activity));
        params.put("payPassword", EncryptUtil.SHA1(payPassword));
        params.put("affirmPassword", EncryptUtil.SHA1(affirmPassword));

        OkHttpUtil.post(activity, URL.URL_SET_PAY_PASSWORD_NEW, "", params, handler, MSG.MSG_SET_PAY_PASSWORD_SUCCESS, MSG.MSG_SET_PAY_PASSWORD_FIELD);

    }

    /**
     * 查询用户是否设置了支付密码
     *
     * @param activity
     * @param handler
     */
    public static void havePayPassword(Activity activity, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("userAccId", UserXML.getUserId(activity)); // "0"-未设置 "1"-已设置

        OkHttpUtil.post(activity, URL.URL_HAVE_PAY_PASSWORD, "加载中...", params, handler, MSG.MSG_HAVE_PAY_PASSWORD_SUCCESS, MSG.MSG_HAVE_PAY_PASSWORD_FIELD);

    }


}
